package me.xplabs.scene 
{
	import flash.net.LocalConnection;
	import me.xplabs.Globals;
	import me.xplabs.build.UpgradeBuildingMediator;
	import me.xplabs.constant.SceneType;
	import me.xplabs.interfaces.IScene;
	import me.xplabs.model.proxy.LoaderMapProxy;
	import me.xplabs.msg.NotificationName;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * ...
	 * @author xiaohan
	 */
	public class SceneCommand extends SimpleCommand 
	{
		private var _curScene:IScene;
		private var _prevScene:IScene;
		private var _prevSceneType:int;
		public function SceneCommand() 
		{
			
		}
		override public function execute(notification:INotification):void 
		{
			if (notification.getBody() == _prevSceneType) return;
			_prevSceneType = int(notification.getBody());
			if (_prevScene) _prevScene.dispose();
			try { 
					new LocalConnection().connect("foo");
					new LocalConnection().connect("foo");
				} catch (e:*) {} 
			switch(notification.getBody())
			{
				case SceneType.LOADER_SCENE:
					_curScene = IScene(facade.retrieveMediator(LoaderSceneMediator.NAME));
					break;
				case SceneType.START_SCENE:
					_curScene = IScene(facade.retrieveMediator(StartSceneMediator.NAME));
					break;
				case SceneType.SELECT_SCENE:
					_curScene = IScene(facade.retrieveMediator(SelectSceneMediator.NAME));
					break;
				case SceneType.GAME_SCENE:
					_curScene = IScene(facade.retrieveMediator(GameSceneMediator.NAME));
					sendNotification(NotificationName.START_DRAWING);
					break;
				//case SceneType.END_SCENE:
					//_curScene = IScene(facade.retrieveMediator(EndSceneMediator.NAME));
					//break;
			}
			_curScene.show();
			_prevScene = _curScene;
		}
	}
}